import mongoose, { Schema, Document } from 'mongoose';
import { IQuestion } from '@shared/types/question';

export interface IQuestionDocument extends Omit<IQuestion, '_id'>, Document {}

const questionSchema: Schema = new Schema({
  content: { type: String, required: true },
  type: { 
    type: String, 
    enum: ['Judgement', 'Select', 'multiSelect'], 
    required: true 
  },
  options: [{
    symbol: { type: String, required: true },
    content: { type: String, required: true }
  }],
  answer: [{ type: Number, required: true }], // 正确答案的索引数组
  score: { type: Number, required: true, min: 1, max: 10 },
  creator: { type: Schema.Types.ObjectId, ref: 'User' },
  create_time: { type: Date, default: Date.now },
  difficulty: { 
    type: String, 
    enum: ['简单', '中等', '困难'], 
    required: true 
  }
});

export const Question = mongoose.model<IQuestionDocument>("Question", questionSchema);
